#include <iostream>
using namespace std;

const int Count = 10;

typedef struct {
    string name;
    float chinese;
    float math;
    float english;
} Student, *Stu;

float average(float grade[], int len)
{
    // ...
    return 0;
}

/**
 * 提高参数参地的效率和安全性
 * 1. 推荐使用引用传递
 * 2. 使用 const 修饰
*/
float getStudentTotle(const Student& stu)
{
    return stu.chinese + stu.math + stu.english;
}


/**
 * 1. 声明变量时尽量在小范围
 * 2. 函数尽量有明确的功能性，代码尽量简短且有通用型
 * 
 * 数组作为参数时
 * 1. 数组作为参数时会退化为指针，将不再知道数组长度
 * 2. 需要将数组长度作为参数一并传递给函数
*/
int main()
{
    Student stu[Count] = {{"Jack",60,86,78},{"Rose",70,65,71},{"Jhon",80,47,26},{"Jackie",90,98,48},{"Henrry",50,84,99},
                          {"Andrew",65,82,88},{"Japenus",54,96,77},{"Lucy",87,98,92},{"Stevin",76,69,95},{"Ganlyee",79,87,91}};

    float ch[Count], ma[Count], en[Count];
    cout << "xxx: " <<  average(ch, Count) << endl;
    cout << "xxx: " <<  average(ma, Count) << endl;
    cout << "xxx: " <<  average(en, Count) << endl;

    float sum[Count] = {0};
    Student *max = nullptr, *min = nullptr;
    for(int i = 0; i < Count; i++) {
        sum[i] = getStudentTotle(stu[i]);
        if(i > 0 && sum[i] > sum[i - 1]) {
            max = &stu[i];
        }
        if(i > 0 && sum[i] < sum[i - 1]) {
            min = &stu[i];
        }
        cout << stu[i].name << " 的总成绩为：" << sum[i] << endl;
    }

    cout << max->name << " 的成绩最高，总分为：" << getStudentTotle(*max) << endl;
    cout << min->name << " 的成绩最低，总分为：" << getStudentTotle(*min) << endl;
    // 找总结最高、最低
    for(int i = 0; i < Count; i++) {
        // ...
    }
    
    return 0;
}